<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<style>
<!--
.pageFormContent label {
	float: none;
}
-->
</style>
<div class="pageContent">
	<s:form cssClass="pageForm required-validate" action="doAdd" name="doAddEmployee" namespace="/employee" method="post" enctype="multipart/form-data" onsubmit="return iframeCallback(this, navTabAjaxDone);">
		<div class="pageFormContent nowrap" layoutH="56">
			<dl>
				<dt>姓名：</dt>
				<dd>
					<s:textfield name="emp.empName" maxlength="100" cssclass="required" />
				</dd>
			</dl>
			<dl>
				<dt>性别：</dt>
				<dd>
					<s:radio cssClass="required" value="0" name="emp.empSex" list="#{'0':'男','1':'女'}" ></s:radio>
				</dd>
			</dl>
			<dl>
				<dt>年龄：</dt>
				<dd>
					<s:select name="emp.empAge" list="{20,22,23,24,25,26,27}" cssclass="required"></s:select>
				</dd>
			</dl>
			<dl>
				<dt>部门：</dt>
				<dd>
					<s:select id="depId" name="emp.dep.depId" headerKey="" headerValue="请选择" list="depList" listKey="depId" listValue="depName"  cssclass="required"></s:select>
				</dd>
			</dl>
			<dl>
				<dt>职位：</dt>
				<dd>
					<select  id="posId" name="emp.pos.posId" class="required">
						<option value="">请选择</option>
					</select>
				</dd>
			</dl>
			<dl>
				<dt>照片:</dt>
				<dd>
				 	<s:file name="photoFile" onchange="selImage(this)"></s:file>
					<!--input type="file" name="photo" onchange="selImage(this)"-->
				</dd>
			</dl>
			<dl>
				<dt></dt>
				<dd>
					<img alt="" id="img" src="" width="200px">
				</dd>
			</dl>
		</div>
		<div class="formBar">
			<ul>
				<!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
				</li>
			</ul>
		</div>
	</s:form>
</div>
<script type="text/javascript">
	$(function(){
		var dep = $("#depId");
		var pos = $("#posId");
		dep.change(function(){
			$.get("../employee/findPositionByDepId.action", {"depId":dep.val()}, function(data){
				pos.empty();
				$.each(data, function(index, obj){
					pos.append("<option value='"+obj.posId+"'>"+obj.posName+"</option>");
				});
			});
		});
	});
	
	function selImage(o) {
		document.getElementById("img").src = getFullPath(o);
	}

	function getFullPath(node){
	 var imgURL = "";
	    try{
	        var file = null;
	        if(node.files && node.files[0] ){
	            file = node.files[0];
	        }else if(node.files && node.files.item(0)) {
	            file = node.files.item(0);
	        }
	        //Firefox 因安全性问题已无法直接通过input[file].value 获取完整的文件路径
	        try{
	            //Firefox7.0
	            imgURL =  file.getAsDataURL();
	            //alert("//Firefox7.0"+imgRUL);
	        }catch(e){
	            //Firefox8.0以上
	            imgURL = window.URL.createObjectURL(file);
	            //alert("//Firefox8.0以上"+imgRUL);
	        }
	    }catch(e){      
	        //支持html5的浏览器,比如高版本的firefox、chrome、ie10
	        if (node.files && node.files[0]) {
	            var reader = new FileReader();
	            reader.onload = function (e) {
	                imgURL = e.target.result;
	            };
	            reader.readAsDataURL(node.files[0]);
	        }
	    }
	    return imgURL;
	}
</script>

